<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
<head>
    <title>医疗机构生成订单 收货地址（医疗机构端）</title>
    <%@ include file="/WEB-INF/component/commonCSS.jsp"%>
</head>

<body class="skin-blue-light sidebar-mini fixed skin-blue-light-frame">

    <section class="content-header">
    </section>
    
    <section class="content">
        <div class=" box box-success">
            <div class="box-body">
                <div class=" form-inline">
                     <div class="form-group form-group-xs">
                        <label for="searchrecpAddr">详细送货地址：</label>
                        <input class="form-control" type="text" id="recpAddr" name="recpAddr" placeholder="详细送货地址" />
                    </div>
                    <button type="button" class="btn btn-success btn-sm" onclick="search()">查  询</button>
                </div>
            </div>
        </div>
        
        <table class="jqgrid" id="gridlist"></table>
        <div id="gridpage"></div>
        
        <div class=" box box-warning bottongroup">
            <button type="button" id="userSelect"  onclick="userSelect();" class="btn btn-primary btn-sm">选择</button>
        </div>
        
    </section>
    
    <%@ include file="/WEB-INF/component/commonJS.jsp"%>
    <script type="text/javascript">

        $(function () {
            var id = "${id}";
            
            $("#gridlist").jqGrid({
                url: "${ctx}/createOrder/getCreateOrderAddress.html",
                mtype: "POST",
                datatype: "json",
                autowidth: true,
                height: 270,
                colNames: ['用户名', '送货地址简称', '详细送货地址', '收货人', '收货人电话'],
                colModel: [
                    { name: 'user.name', width: 120 , align:"center" ,sortable: false},
                    { name: 'recpAddrS', width: 80 , align:"center" ,sortable: false},
                    { name: 'recpAddr', width: 150 , align:"center" ,sortable: false},
                    { name: 'recpUser', width: 60 , align:"center" ,sortable: false},
                    { name: 'recpUserphone', width: 80 , align:"center",sortable: false }
                ],
                rowNum: 20,
                rowList: [10, 20, 30,50,100],
                rownumbers: true,
                multiselect: false,
                pager: "#gridpage",
                viewrecords: true,
                caption: "用户列表 ",
                jsonReader: {
                    repeatitems: false,
                    id: "recpAddrId"
                },
                gridComplete: function() {
                    var ids = $("#gridlist").jqGrid('getDataIDs');
                    if (ids.length > 0) {
                        for (var i=0; i<ids.length; i++) {
                            var temp = ids[i];
                            if (id == temp) {
                                $("#gridlist").setSelection(id);
                            }
                        }
                    }
                }
            });
            $("#gridlist").jqGrid('navGrid', '#gridpage', { add: false, edit: false, del: false, search: false, refresh: false });
            $(window).trigger("resize");
        });
        
        /* 查询 */
        function search(page) {
            var username = $.trim($("#username").val());
            var name = $.trim($("#name").val());
            var recpAddr = $.trim($("#recpAddr").val());
            $("#gridlist").jqGrid("clearGridData");
                $("#gridlist").jqGrid('setGridParam',{  
                mtype: "POST",
                datatype:'json',
                postData:{"username":username,"name":name,"recpAddr":recpAddr},
                page : (page || 1)
            }).trigger("reloadGrid"); //重新载入  
        }
        
        /* 选择 */
        function userSelect(){
            var rowId = $("#gridlist").jqGrid("getGridParam", "selrow");
            if (rowId == null || rowId == "") {
                $.HN.message.alert('请选择详细收货地址！', '提示信息', 'warn');
                return ;
            }
            var rowdata = $("#gridlist").jqGrid('getRowData', rowId);
            var params = {"recpAddrId":rowId, "recpAddr":(rowdata.recpAddr || "")};
            var dialog = top.dialog.get(window);
            dialog.close(params); // 关闭（隐藏）对话框
            dialog.remove();      // 主动销毁对话框
            return false;
        }
        
        
    </script>
</body>
</html>